package com.numberone.master.modules.card.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.numberone.master.common.Interface.ShanDong;
import com.numberone.master.common.persistence.Page;
import com.numberone.master.common.service.CrudService;
import com.numberone.master.common.utils.JsonUtils;
import com.numberone.master.modules.card.entity.Card;
import com.numberone.master.modules.card.dao.CardDao;

/**
 * 物联网卡Service
 * @author chegkang
 * @version 2018-02-01
 */
@Service
@Transactional(readOnly = true)
public class CardService extends CrudService<CardDao, Card> {
	
	@Autowired
	private CardDao cardDao;
	
	
	public Card get(String id) {
		Card card = super.get(id);
		return card;
	}
	
	public List<Card> findList(Card card) {
		return super.findList(card);
	}
	
	public Page<Card> findPage(Page<Card> page, Card card) {
		Page<Card> findPage = super.findPage(page, card);
		return findPage;
	}
	
	@Transactional(readOnly = true)
	public Page<Card> findAgainPageList(Page<Card> page, Card card) {
		card.setPage(page);
		Page<Card> pages = page.setList(findAgainList(card));
		return pages;
	}
	
	@Transactional(readOnly = true)
	public List<Card> findAgainList(Card card){
		return cardDao.findAgainList(card);
	}
	
	
	@Transactional(readOnly = false)
	public void save(Card card) {
		super.save(card);
	}
	
	@Transactional(readOnly = false)
	public void delete(Card card) {
		super.delete(card);
	}
	
	@Transactional(readOnly = false)
	public List<Card> findCardList(Card card){
		return cardDao.findCardList(card);
	}
	
	@Transactional(readOnly = false)
	public void distribution(String  id,String officeId){
		cardDao.distribution(id,officeId);
	}
	
	@Transactional(readOnly = false)
	public void updateSetUser(Card card){
		cardDao.updateSetUser(card);
	}
	
	@Transactional(readOnly = false)
	public void updateThreshold(Card card){
		cardDao.updateThreshold(card);
	}
	
	@Transactional(readOnly = true)
	public Card getCardByCCID(String iccid,String id){
		return cardDao.getCardByCCID(iccid, id);
	}
	
	@Transactional(readOnly = true)
	public Card getCardInfoByCCID(String iccid){
		return cardDao.getCardInfoByCCID(iccid);
	}
	
	@Transactional(readOnly = true)
	public int getCardByIds(String ids,String pkg){
		Integer count = cardDao.getCardByIds(ids,pkg);
		return count;
	}
	
	@Transactional(readOnly = true)
	public String getCardInfo(String iccid,String ebid){
		//根据iccid查询卡编号
		Card card = cardDao.getCardInfoByCCID(iccid);
		String res = "";
		//流量卡状态
		if(StringUtils.equals("0001000000009", ebid)){
			 res = ShanDong.qryCardStatusResult(card.getPhonenumber(), "531");
		}
		//卡的流量查询
		if(StringUtils.equals("0001000000083", ebid)){
			 res = ShanDong.qryGPRSRealTimeInfo(card.getPhonenumber(), "1", "531");
		}
		return res;
	}
}